#pragma once
#include <set>
#include "BaseTracker.hxx"
#include "KalmanTracker.hxx"


typedef struct TrackingBox
{
	int frame;
	int id;
	Rect_<float> box;
}TrackingBox;

class SORTTracker :
    protected BaseTracker
{
public:
    SORTTracker();

    void update(std::vector<DetectedObject>& retObjs);

	vector<TrackingBox> getTrackingResults();
private:
	//TrackingBox detectedObject2TrackingBox(DetectedObject& obj);
	void initialize(std::vector<DetectedObject>& retObjs);

	void predict();

	void associate(std::vector<DetectedObject>& retObjs);

	void update_(std::vector<DetectedObject>& retObjs);

private:
	int _maxAge;
	int _minHits;
	double _iouThreshold;
	vector<KalmanTracker> _trackers;

	// variables used in the for-loop
	vector<Rect_<float>> _predictedBoxes;
	vector<vector<double>> _iouMatrix;
	vector<int> _assignment;
	set<int> _unmatchedDetections;
	set<int> _unmatchedTrajectories;
	set<int> _allItems;
	set<int> _matchedItems;

	vector<cv::Point> _matchedPairs;
	vector<TrackingBox> _frameTrackingResult;

	unsigned int _trkNum;
	unsigned int _detNum;
};
